﻿using System.Drawing;
using System.Windows.Forms;
using Janus.Windows.EditControls;

namespace HiStaff.Control
{
    [ToolboxBitmap(typeof(CheckBox))]
    public class HiCheckBox : UICheckBox
    {
        private bool _readOnly = false;
        private bool _checkStatusReadOnly = false;
        private bool _readOnlyWhenEdit = false;
        private bool _searchControl = false;
        public bool SearchControl
        {
            get { return _searchControl; }
            set { _searchControl = value; }
        }
        public bool ReadOnlyWhenEdit
        {
            get { return _readOnlyWhenEdit; }
            set { _readOnlyWhenEdit = value; }
        }
        public bool ReadOnly
        {
            get { return _readOnly; }
            set { _readOnly = value; }
        }
        public string DataField { get; set; }
        public decimal? Value
        {
            get
            {
                return this.Checked ? 1 : 0;
            }
            set
            {
                this.Checked = value == 1;
            }
        }
        public HiCheckBox()
        {
            this.VisualStyle = Janus.Windows.UI.VisualStyle.Office2010;
        }
        protected override void OnCheckedChanged(System.EventArgs e)
        {
            if (_readOnly)
            {
                if (!_checkStatusReadOnly)
                {
                    _checkStatusReadOnly = true;
                    this.Checked = !this.Checked;
                }
                else
                {
                    _checkStatusReadOnly = false;
                }
            }
            else
            {
                base.OnCheckedChanged(e);
            }
        }
    }
}
